'use strict';

const Controller = require('egg').Controller;
class TestController extends Controller {
  async test1 () {
    const { ctx } = this;
    await new Promise(resolve => {
      setTimeout(() => {
        resolve(ctx.body = '异步请求');
      }, 5000);
    });
  }

  //   get自由传参模式
  async test2 () {
    const ctx = this.ctx;
    const id = ctx.query.id;
    const res = await ctx.service.test.test1(id);
    ctx.body = res;
  }

  //   get严格传参模式 多一个少一个都不行
  async test3 () {
    const ctx = this.ctx;
    ctx.body = '我是' + ctx.params.name + ',今年' + ctx.params.age + '岁';
  }
  // post
  async testurl () {
    const ctx = this.ctx;
    const data = ctx.request.body;
    console.log('cometesturl====', data);
    const res = await ctx.service.test.testurl(data);
    ctx.body = res;
  }
  // geturl
  async geturl () {
    const data = this.ctx.query;
    console.log(data);
    const { ctx } = this;
    const res = await ctx.service.test.geturl(data);
    ctx.body = res;
  }
  // 测试testjwt
  async testjwt () {
    const data = this.ctx.query;
    console.log(data);
    const { ctx, app } = this;
    if (data.username == 'caijunyi' && data.password == 'caijunyi') {
      const token = app.jwt.sign({
        username: data.username,
      }, app.config.jwt.secret, {
        expiresIn: '25s',
      });
      ctx.body = {
        code: 0,
        token,
      };
    } else {
      ctx.body = {
        code: -200,
        message: '账号或密码错误',
      };
    }
  }
  // testjwtlogin
  async testjwtlogin () {
    const data = this.ctx.query;
    const { ctx } = this;
    console.log(data);
    ctx.body = {
      code: 200,
      message: `传入数据为${data}`,
    };
  }
  // testjwtloginpost
  async testjwtloginpost () {
    const ctx = this.ctx;
    const data = ctx.request.body;
    ctx.body = {
      code: 200,
      message: `post传入数据为${data}`,
    };
  }
  async posttest () {
    const ctx = this.ctx;
    const data = ctx.request.body;
    const res = await ctx.service.test.posttest(data);
    ctx.body = res;
  }
  async getnowdatatest () {
    const data = this.ctx.query;
    const { ctx } = this;
    const res = await ctx.service.test.getnowdatatest(data);
    ctx.body = res;
  }

  // 数据可视化test
  async maptest () {
    // const res = await this.app.mysql.query('select * from users where username=? ', ['1']);
    const ctx = this.ctx;
    ctx.body = {
      code: 200,
      data: [
        {
          documentNo: '137727202107230004',
          downEntrustNo: 'C0113002021072300001',
          carNo: '晋DE1849',
          warehouseNo: 'W1323',
          warehouseName: '北京食品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100580959',
          customerName: '长治市日盛达商贸有限公司',
          customerAddr: '山西省长治市城　区长安路35号（纺织品有限公司西仓库）纺织品有限公司',
          longitude: '113.11260402784855',
          latitude: '36.19969390872952',
          orderDeliveryTime: '',
        },
        {
          documentNo: '137727202107230007',
          downEntrustNo: 'C0113002021072300001',
          carNo: '晋DE1849',
          warehouseNo: 'W1323',
          warehouseName: '北京食品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100580959',
          customerName: '长治市日盛达商贸有限公司',
          customerAddr: '山西省长治市城　区长安路35号（纺织品有限公司西仓库）纺织品有限公司',
          longitude: '113.11260402784855',
          latitude: '36.19969390872952',
          orderDeliveryTime: '',
        },
        {
          documentNo: '137727202107230009',
          downEntrustNo: 'C0113002021072300001',
          carNo: '晋DE1849',
          warehouseNo: 'W1323',
          warehouseName: '北京食品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100580959',
          customerName: '长治市日盛达商贸有限公司',
          customerAddr: '山西省长治市城　区长安路35号（纺织品有限公司西仓库）纺织品有限公司',
          longitude: '113.11260402784855',
          latitude: '36.19969390872952',
          orderDeliveryTime: '',
        },
        {
          documentNo: '137727202107230010',
          downEntrustNo: 'C0113002021072300001',
          carNo: '晋DE1849',
          warehouseNo: 'W1323',
          warehouseName: '北京食品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100580959',
          customerName: '长治市日盛达商贸有限公司',
          customerAddr: '山西省长治市城　区长安路35号（纺织品有限公司西仓库）纺织品有限公司',
          longitude: '113.11260402784855',
          latitude: '36.19969390872952',
          orderDeliveryTime: '',
        },
        {
          documentNo: '137727202107230011',
          downEntrustNo: 'C0113002021072300001',
          carNo: '晋DE1849',
          warehouseNo: 'W1323',
          warehouseName: '北京食品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100580959',
          customerName: '长治市日盛达商贸有限公司',
          customerAddr: '山西省长治市城　区长安路35号（纺织品有限公司西仓库）纺织品有限公司',
          longitude: '113.11260402784855',
          latitude: '36.19969390872952',
          orderDeliveryTime: '',
        },
        {
          documentNo: '1381DK202107140002',
          downEntrustNo: 'C0113002021071400010',
          carNo: '津C28983',
          warehouseNo: 'W1301',
          warehouseName: '北京饮品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100888580',
          customerName: '北京京东世纪信息技术有限公司',
          customerAddr: '天津市北辰区陆路港嘉民物流园京东仓库13库',
          longitude: '117.3345160484151',
          latitude: '39.25502813752891',
          orderDeliveryTime: '2021-07-16 11:48:23',
        },
        {
          documentNo: '1381DK202107140012',
          downEntrustNo: 'C0113002021071400010',
          carNo: '津C28983',
          warehouseNo: 'W1301',
          warehouseName: '北京饮品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100888580',
          customerName: '北京京东世纪信息技术有限公司',
          customerAddr: '天津市北辰区陆路港嘉民物流园京东仓库13库',
          longitude: '117.3345160484151',
          latitude: '39.25502813752891',
          orderDeliveryTime: '2021-07-16 11:48:23',
        },
        {
          documentNo: '1381DK202107140013',
          downEntrustNo: 'C0113002021071400010',
          carNo: '津C28983',
          warehouseNo: 'W1301',
          warehouseName: '北京饮品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100888580',
          customerName: '北京京东世纪信息技术有限公司',
          customerAddr: '天津市北辰区陆路港嘉民物流园京东仓库13库',
          longitude: '117.3345160484151',
          latitude: '39.25502813752891',
          orderDeliveryTime: '2021-07-16 11:48:23',
        },
        {
          documentNo: '1381DK202107140014',
          downEntrustNo: 'C0113002021071400010',
          carNo: '津C28983',
          warehouseNo: 'W1301',
          warehouseName: '北京饮品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100888580',
          customerName: '北京京东世纪信息技术有限公司',
          customerAddr: '天津市北辰区陆路港嘉民物流园京东仓库13库',
          longitude: '117.3345160484151',
          latitude: '39.25502813752891',
          orderDeliveryTime: '2021-07-16 11:48:23',
        },
        {
          documentNo: '1381DK202107140015',
          downEntrustNo: 'C0113002021071400010',
          carNo: '津C28983',
          warehouseNo: 'W1301',
          warehouseName: '北京饮品成品仓',
          start_long: '116.654041',
          start_lat: '40.341968',
          customerCode: 'A0100888580',
          customerName: '北京京东世纪信息技术有限公司',
          customerAddr: '天津市北辰区陆路港嘉民物流园京东仓库13库',
          longitude: '117.3345160484151',
          latitude: '39.25502813752891',
          orderDeliveryTime: '2021-07-16 11:48:23',
        },
      ],
    };
  }
}

module.exports = TestController;
